package com.solcoo.util;

import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.solcoo.dao.SOBDao;
import com.solcoo.pojo.SOB;

@Component("sobUtil")
public class SOBUtil {

	@Resource
	private SOBDao sobDao;
	
    public Boolean checkSOB(String SOB) throws Exception {
    	if(SOB==null || "".equals(SOB.trim())) {
    		return false;
    	}
    	SOB existSOB = sobDao.getSOB(SOB);
    	if(existSOB != null) {
    		return false;
    	}
    	if(!("99".equals(SOB.substring(13,15)) && "1".equals(SOB.substring(3, 4)))) {
    		return false;
    	}
    	String sob2 = SOB.substring(0,6) + SOB.substring(7,SOB.length());
    	StringBuffer sb = new StringBuffer();
    	sb.append(sob2.substring(12,sob2.length()));
    	sb.append(sob2.substring(8,12));
    	sb.append(sob2.substring(4,8));
    	sb.append(sob2.substring(0,4));
    	sb.delete(0, 2);
    	sb.delete(sb.length()-1, sb.length());
    	Long submitTime = Long.parseLong(sb.toString());
    	
    	Long subTime = (System.currentTimeMillis() - submitTime) / 1000;

    	if(subTime<300 && subTime>-300) {
    		existSOB = new SOB();
    		existSOB.setShijian(new Date());
    		existSOB.setSob(SOB);
    		sobDao.addSOB(existSOB);
    		return true;
    	}
    	
    	return false;
    }
}
